package entity

import (
	"shqsoft.cn/pasnj/base"

	"github.com/jinzhu/gorm"
)

//GJJSLDR 国际结算量导入
type GJJSLDR struct {
	ID    int     `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	KHYF  int     `gorm:"column:KHYF"`
	KHJL  string  `gorm:"column:KHJL;size:100"`
	FKJDZ float64 `gorm:"column:FKJDZ"`
	KJDZ  float64 `gorm:"column:KJDZ"`
}

//GjjslBeforeImportValidation 导入前执行，验证数据
// func GjjslBeforeImportValidation(index int, rowdatas []string) []base.ErrorData {
// 	log.Debug(rowdatas)
// 	errDatas := make([]base.ErrorData, 1, 1)
// 	errInfos := make([]base.ErrorInfo, 1, 1)
// 	errinfo := base.ErrorInfo{
// 		ColIndex: 0,
// 		Message:  "客户经理错误或不存在！",
// 	}
// 	errInfos[0] = errinfo
// 	errData := base.ErrorData{
// 		RowIndex:   index,
// 		DataValues: rowdatas,
// 		ErrorInfos: errInfos,
// 	}
// 	errDatas[0] = errData
// 	return errDatas
// }

//GjjslAfterImport 导入后执行
func GjjslAfterImport(tx *gorm.DB, params map[string]string) (err error) {
	err = tx.Exec("UPDATE T_BASE_YXFY_GJJSL SET EMID=B.ID "+
		"FROM T_BASE_YXFY_GJJSL A INNER JOIN T_SysUser B ON (A.KHJL=B.SysUserName) OR (A.KHJL=B.SysUserID)"+
		"WHERE KHYF=?", params["KHYF"]).Error
	if err != nil {
		return err
	}
	return nil
}

//TableName 国际中收导入表
func (GJJSLDR) TableName() string {
	return "T_BASE_YXFY_GJJSL"
}

//GJJSLDREF 返回结构体
func GJJSLDREF() base.EntityFunc {
	return func() interface{} {
		entity := GJJSLDR{}
		return &entity
	}
}

//GJJSLDRESF 返回结构体数组
func GJJSLDRESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []GJJSLDR
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("GJJSLDR", base.NewDefaultDao(GJJSLDREF(), GJJSLDRESF(), nil))
	base.SetAfterCallBack("GJJSLDR", GjjslAfterImport)

}
